<template>
	<div class="wy-main business-car-manage wei_business_car_manage">
		<a-row class="wy-main-title">
			<a-col :span="24">
				<p class="title-p">
					<a-divider class="title-vertical"  type="vertical" />
					<span class="title-span" >管理我的车源</span>
					<a-divider class="title-divider"  />
				</p>
			</a-col>
		</a-row>
		<div>
			<a-input style="width: 200px;"  @click="departureShowMap" placeholder="请输入起始地查询" v-model="beginPlace"/>
			<a-input style="width: 200px;"  @click="destinationShowMap"  placeholder="请输入目的地查询" v-model="endPlace"/>
			<a-button type="primary" style="margin-left: 10px;" @click="getcarSource">点击查询</a-button>
			<a-button style="margin-left: 10px;" @click="reset">重置信息</a-button>
			<!--<router-link to="/business/car/publish">
				<a-button type="primary" style="float: right;">新增车源</a-button>
			</router-link>-->
			<router-link to="/business/car/publish">
				<a-button type="primary" class="wy-m-l-10 wy-float-r"  v-hasPermission="'Vsource:add'">新增车源</a-button>
			</router-link>
			<a-button type="primary" class="wy-m-l-10 wy-float-r"  v-hasPermission="'Vsource:add2'" @click="$refs.autoError.handleShow()">新增车源</a-button>
		</div>
		<div class="route_choice manage_car">
			<a-table :columns="columns" :dataSource="cardata" :rowKey="record => record.vehicleinfoId" :pagination="pagination"  @change="handleTableChange"  :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
					
				 <!-- <span slot="status" slot-scope="text, record" style="color:red">
             <span v-if="record.status==0">未处理</span>
             <span v-if="record.status==1">通过</span>
						 <span v-if="record.status==2">不通过</span>
        </span> -->
				<span slot="type" slot-scope="text, record" >
		             <span v-if="record.type==0">本地车</span>
		             <span v-if="record.type==1">回程车</span>	 
		        </span>
				<span slot="approvalStatusValue" slot-scope="text,record">
				  	<span v-if="text == '待审批'" style="color: #ffa60b;">待审核</span>
				  	<span  v-if="text == '不通过'" style="color:  #ff2f47;">审核失败</span>
				  	<span v-if="text == '通过'" style="color: #15837A;">审核通过</span>
			    </span>
				<span slot="action" slot-scope="text, record">
			      <a href="javascript:;" @click="seeInfo(record)">查看</a>
			      <!-- <a-divider type="vertical" v-if="record.approvalStatusValue == '不通过'" /> -->
			      <a href="javascript:;" @click="edit(record)" v-if="record.approvalStatusValue == '不通过'"> 修改</a>
			      <!-- <a-divider type="vertical" /> -->
			      <a href="javascript:;" @click="delcarSource(record)" > 删除</a>
			    </span>
				 <span slot="releaseDateSplit" slot-scope="text, record">
                <span v-if="!!record.createTime">{{record.createTime.split(" ")[0]}}</span>
              </span>
			</a-table>
		</div>
		<div style='margin-top: -50px;'>
			<a-button @click="delcars">删除所选</a-button>
		</div>
		<a-modal :title="type == 'edit' ? '编辑车源信息' : '查看车源信息'"  :visible="visible" @cancel="handleCancel" width="900px" :maskClosable='false' :footer="null" >
			<publish-add v-if="visible" 
			  :isSee='isSee' :datail='datail' @close="close" :type='type'></publish-add>
		</a-modal>
				<a-modal  :visible="auditShow" @cancel="auditclose" width="500px"  :maskClosable='false' :footer="null">
			<audit  v-if="auditShow" @cancelaudit="auditclose"></audit>
		</a-modal>
		<map-svg ref="mapSvgDialog" @change="mapSvgCall" @distance="distanceCall"></map-svg>
		<!--未认证弹窗-->
		<auto-error  ref="autoError" ></auto-error>
	</div>
</template>
<script>
	import MapSvg from '@/components/dialog/MapSvg'
	import publishAdd from './Publish'
	import Audit from '@/components/tool/audit'
	import AutoError from '@/components/dialog/AutoError'
	const columns = [{
		title: '车牌号',
		dataIndex: 'licence',
		width:100,
		key: 'licence',
	},{
		title: '车源类型',
		dataIndex: 'type',
		scopedSlots: {
			customRender: 'type'
		},
		width:100,
		key: 'type'

	},{
		title: '出发地',
		dataIndex: 'beginPlace',
		key: 'beginPlace',
		scopedSlots: {
			customRender: 'beginPlace'
		},
		width:140,
	},{
		title: '到达地',
		dataIndex: 'endPlace',
		key: 'endPlace',
		scopedSlots: {
			customRender: 'endPlace'
		},
		width:140,
	},{
		title: '驾驶员',
		dataIndex: 'driverName',
		key: 'driverName',
		width:100,
	},{
		title: '驾驶员联系电话',
		dataIndex: 'driverMobile',
		key: 'driverMobile',
		width:140,
	},{
		title: '车辆常驻地',
		dataIndex: 'residence',
		key: 'middlePlace',
		width:140,
	},{
		title: '审核状态',
		dataIndex: 'approvalStatusValue',
		key:'approvalStatusValue',
		width:100,
		scopedSlots: {
		 	customRender: 'approvalStatusValue'
		}
	},{
		title: '发布日期',
		dataIndex: 'createTime',
		width:100,
		key: 'createTime',
		    scopedSlots: {
      customRender: 'releaseDateSplit'
    },
	},
	{
		title: '操作',
		width:170,
		key: '0',
		scopedSlots: {
			customRender: 'action'
		},
	}];

	export default {
		data() {
			return {
				isSee:true,
				auditShow:false,
				beginPlace:'',
				endPlace:'',
				type:'',
				visible:false,
				datail:{},
				cardata:[],
				columns,
				loading: false,
				pagination: {
				  pageSizeOptions: ['10', '20', '30', '40', '100'],
				  defaultCurrent: 1,
				  defaultPageSize: 10,
				  total:0,
				  showSizeChanger: true,
				  showTotal: (total, range) => `共 ${total} 条记录`
				},
			    selectedRowKeys: [],
			}
		},
		computed: {
			auditShowes:function(){
				console.log(333222)
				 this.auditShow=true
			}
		},
		beforeCreate() {},
		created() {
			this.getcarSource()
		},
		components: {
			publishAdd,
			Audit,
			MapSvg,
			AutoError
		},
		watch: {

		},

		mounted: function() {

		},
		methods: {
			/* 省市地图代码 start */
			// 省市地图回调
			mapSvgCall(d) {
				if(d.name === 'departure') {
					this.beginPlace = d.provCityArea
				}
				if(d.name === 'destination') {
					this.endPlace = d.provCityArea
				}
			},
			// 起运地
			departureShowMap() {
				this.$refs.mapSvgDialog.mapSvgVisible('departure', 2, '', '', '');
			},
			// 目的地
			destinationShowMap() {
				this.$refs.mapSvgDialog.mapSvgVisible('destination', 2, '', '', '');
			},
			// 调用距离返回
			distanceCall(num) {
				// this.form.setFieldsValue({ juliNum: num });
			},
			/* 省市地图代码 end */
			reset(){
				this.beginPlace = '',
				this.endPlace = ''
				this.getcarSource()
			},
			// 修改完成关闭刷新数据
			close(data){

				this.visible = false

				this.getcarSource()

						if(data==1){
					this.auditShow = true
				}
			},
			// 查看货物信息
			seeInfo(data){
				this.type = 'info'
				this.visible = true
		        this.datail = data
						this.isSee = true
			},
			// 编辑货物信息
			edit(data){
				this.type = 'edit'
				this.visible = true
		        this.datail = data
						this.isSee = false
			},
			// 关闭弹窗
			handleCancel(){
				this.visible = false
			},
			// 删除多条信息
			delcars(){
				 if (!this.selectedRowKeys.length) {
				  this.$message.warning('请选择需要删除的记录')
				  return
				}
				let that = this
				this.$confirm({
				  title: '确定删除所选中的记录?',
				  content: '当您点击确定按钮后，这些记录将会被彻底删除',
				  centered: true,
				  onOk () {
				    let logIds = that.selectedRowKeys
//				    for (let key of that.selectedRowKeys) {
//				      logIds.push(that.cardata[key].vehicleinfoId)
//				    }
					that.$delete('/info/infoVehicleinfo/' + logIds.join(',')).then(() => {
				      that.$message.success('删除成功')
				      that.selectedRowKeys = []
				      that.getcarSource()
				    })
				  },
				  onCancel () {
				    that.selectedRowKeys = []
				  }
				})
			},
			auditclose(){
				this.auditShow=false;

			},
			// 删除单条信息
			delcarSource(data){
				console.log(data)
				let that = this
				this.$confirm({
				  title: '确定删除所选中的记录?',
				  content: '当您点击确定按钮后，这些记录将会被彻底删除',
				  centered: true,
				  onOk () {
				    let logIds = []
				    logIds.push(data.vehicleinfoId)
				    that.$delete('/info/infoVehicleinfo/' + logIds.join(',')).then(() => {
				      that.$message.success('删除成功')
				      that.selectedRowKeys = []
				      that.getcarSource()
				    })
				  },
				  onCancel () {
				    that.selectedRowKeys = []
				  }
				})
			},
			// 获取车源信息列表
			getcarSource(params={}){
				params.pageSize = this.pagination.defaultPageSize
				params.pageNum = this.pagination.defaultCurrent
				params.beginPlace = this.beginPlace
				params.endPlace = this.endPlace
//				this.$get('/info/infoVehicleinfo', params).then((r) => {
				this.$get('/info/infoVehicleinfo/getVehicleinfoList', params).then((r) => {
					console.log(r)
					this.cardata = r.data.data.rows
					this.pagination.total = r.data.data.total
				})
			},
			// 全选事件
			onSelectChange (selectedRowKeys) {
		      console.log('selectedRowKeys changed: ', selectedRowKeys);
		      this.selectedRowKeys = selectedRowKeys
		    },
			// 表格排序 分页 筛选事件
			handleTableChange (pagination, filters, sorter) {
			   this.pagination.defaultPageSize = pagination.pageSize
			   this.pagination.defaultCurrent  = pagination.current
			   this.getcarSource()
			},
		}
	}
</script>

<style lang="less" scoped>
	.business-car-manage {
		.route_choice {
			margin-top: 20px;
		}
	}
</style>